package OrderService

import (
	"context"
	toolsDb "gdshop-back-end-go/common/db"
	"gdshop-back-end-go/common/entity"
	"github.com/gogf/gf/frame/g"
	"time"
)

func CloseOneDayNoPayOrder() {
	ctx := context.Background()
	var oList []*entity.Order
	err := toolsDb.GetUnSafaTableAddDeleteWhere(ctx, "order").Where(
		"status = 1 AND create_at < ?",
		time.Now().Unix()-86400).Structs(&oList)
	if err != nil {
		g.Log().Async().Cat("closeOneDayOrder").Error("失败：", err)
		return
	}
	if oList == nil {
		g.Log().Async().Cat("closeOneDayOrder").Info("没有需要关闭的订单")
		return
	}
	for _, item := range oList {
		jieguo := CloseNoPayOrder(ctx, item.Id)
		g.Log().Async().Cat("closeOneDayOrder").Info("关闭结果：", jieguo)
	}
}
